home *** CD-ROM | disk | FTP | other *** search
/ Merciful 2 / Merciful - Disc 2.iso / software / d / devioustools19.dms / devioustools19.adf / utils / 005.lzx / CompactPlayer / Source / ConfWindow.c < prev    next >
C/C++ Source or Header  |  1978-01-22  |  7KB  |  334 lines

  1. #include "sysheaders.h"
  2. #include "cdpanel.h"
  3. #include "CompactPlayer.h"
  4.  
  5. /********************************************************
  6.  * CD Index editor
  7.  */
  8.  
  9. struct Window *ConfWin;
  10. Object *ConfWinObj;
  11. struct Gadget *ConfLayout;
  12. struct List *DeviceList;
  13. struct List *UnitList;
  14.  
  15. STRPTR Devs[64];
  16. STRPTR Units[8];
  17. LONG UnitIDs[8];
  18.  
  19. static ULONG device;
  20. static ULONG unit;
  21.  
  22. UBYTE UnitNames[7][26];
  23.  
  24. static STRPTR AvoidNames[] = 
  25. {
  26.     "audio.device",         /* System devices we want to skip */
  27.     "clipboard.device",
  28.     "console.device",
  29.     "gameport.device",
  30.     "input.device",
  31.     "keyboard.device",
  32.     "parallel.device",
  33.     "printer.device",
  34.     "ramdrive.device",
  35.     "serial.device",
  36.     "timer.device",
  37.     "trackdisk.device",
  38.     "mfm.device",
  39.  
  40.     "bootdisk.device",      /* Other devices that we don't want */
  41.     "modem0.device",
  42.     "modem1.device",
  43.     "modem2.device",
  44.     "modem3.device",
  45.     "pit.device",
  46.     "duart.device",
  47.     "ppp.device",
  48.     "slip.device",
  49.     "cslip.device",
  50.     "rhslip.device",
  51.     "rhcslip.device",
  52.     "a2060.device",
  53.     "a2065.device",
  54.  
  55.     NULL
  56. };
  57.  
  58. BOOL
  59. AvoidDevice(STRPTR s)
  60. {
  61.     STRPTR *a = AvoidNames;
  62.     
  63.     while (*a)
  64.     {
  65.         if (!strcmp(*a++, s))
  66.             return TRUE;
  67.     }
  68.     return FALSE;
  69. }
  70.  
  71. struct List *
  72. MakeDeviceList(void)
  73. {
  74.     struct Node *n;
  75.     LONG i = 0;
  76.  
  77.     Forbid();
  78.     
  79.     for (n = SysBase->DeviceList.lh_Head; n->ln_Succ; n = n->ln_Succ)
  80.     {
  81.         if (!AvoidDevice(n->ln_Name))
  82.             Devs[i++] = n->ln_Name;
  83.     }
  84.     Permit();
  85.     Devs[i] = NULL;
  86.     
  87.     return BrowserNodesA(Devs);
  88. }
  89.  
  90. struct List *
  91. MakeUnitList(STRPTR device)
  92. {
  93.     struct MsgPort *mp;
  94.     struct IOStdReq *io;
  95.     struct List *l;
  96.     BOOL CD[8];
  97.     
  98.     Units[0] = NULL;
  99.     
  100.     if (mp = CreateMsgPort())
  101.     {
  102.         if (io = CreateIORequest(mp, sizeof(struct IOStdReq)))
  103.         {
  104.             LONG i, j = 0;
  105.             static SCSICMD6 command = { SCSI_INQUIRY };
  106.             static struct SCSICmd ScsiCmd;
  107.             UBYTE data[80];
  108.             
  109.             if (ConfWinObj)
  110.                 SetAttrs(ConfWinObj, WA_Title, GS(PLEASE_WAIT), TAG_END);
  111.             
  112.             for (i = 0; i < 8; i++)
  113.             {
  114.                 if (!OpenDevice(device, i, (struct IORequest *)io, 0L))
  115.                 {
  116.                     command.b4 = 40;
  117.                     
  118.                     ScsiCmd.scsi_Command = (UBYTE *)&command;
  119.                     ScsiCmd.scsi_CmdLength = sizeof(command);
  120.                     ScsiCmd.scsi_Data = (UWORD *)data;
  121.                     ScsiCmd.scsi_Length = sizeof(data)/2;
  122.                     ScsiCmd.scsi_Flags = SCSIF_READ;
  123.                     
  124.                     io->io_Command = HD_SCSICMD;
  125.                     io->io_Data = &ScsiCmd;
  126.                     io->io_Length = sizeof(ScsiCmd);
  127.             
  128.                     DoIO((struct IORequest *)io);
  129.                     
  130.                     if (!io->io_Error)
  131.                         Sprintf(UnitNames[i], "%-8.8s %-16.16s", &data[8], &data[16]);
  132.                     else
  133.                         Sprintf(UnitNames[i], GS(ERROR));
  134.                     
  135.                     Units[j] = UnitNames[i];
  136.                     CD[j] = (BOOL)(((data[0] & 0x1f) == 0x05) ? TRUE : FALSE); /* is a CD-ROM */
  137.                     UnitIDs[j++] = i;
  138.  
  139.                     CloseDevice(io);
  140.                 }
  141.             }
  142.             Units[j] = NULL;
  143.         
  144.             if (ConfWinObj)
  145.                 SetAttrs(ConfWinObj, WA_Title, GS(CONFIGURATION), TAG_END);
  146.             
  147.             DeleteIORequest(io);
  148.         }
  149.         DeleteMsgPort(mp);
  150.     }
  151.     l = BrowserNodesA(Units);
  152.     {
  153.         struct Node *n = l->lh_Head;
  154.         LONG i = 0;
  155.         
  156.         while (n->ln_Succ)
  157.         {
  158.             if (CD[i])
  159.                 SetListBrowserNodeAttrs(n, LBNA_Flags, LBFLG_CUSTOMPENS, LBNCA_FGPen, 2, TAG_END);
  160.         
  161.             n = n->ln_Succ; i++;
  162.         }
  163.     }
  164.     return l;
  165. }
  166.  
  167. struct Window *
  168. OpenConfWindow(ULONG X, ULONG Y)
  169. {
  170.     if (ConfWin)
  171.         return ConfWin;
  172.  
  173.     /* Two listviews with a button below the left side list */
  174.         
  175.     ConfLayout = HGroupObject, LAYOUT_SpaceOuter, TRUE,
  176.         GA_DrawInfo, Dri,
  177.         LAYOUT_DeferLayout, TRUE,
  178.         StartVGroup,
  179.             StartMember, GList[G_Device] = ListBrowserObject,
  180.                 LISTBROWSER_Labels, &dummyList,
  181.                 LISTBROWSER_ShowSelected, TRUE,
  182.                 GA_RelVerify, TRUE,
  183.                 GA_ID, G_Device,
  184.                 End,
  185.                 CHILD_MinWidth, ScreenFont->tf_XSize * 12,
  186.             StartMember, GList[G_Select] = ButtonObject,
  187.                 GA_Text, GS(B_USE_THIS),
  188.                 GA_ID, G_Select,
  189.                 GA_RelVerify, TRUE,
  190.                 End,
  191.                 CHILD_WeightedHeight, 0,
  192.             EndGroup,
  193.             CHILD_WeightedWidth, 0,
  194.         StartMember, GList[G_Unit] = ListBrowserObject,
  195.             LISTBROWSER_Labels, &dummyList,
  196.             LISTBROWSER_ShowSelected, TRUE,
  197.             GA_RelVerify, TRUE,
  198.             GA_ID, G_Unit,
  199.             GA_Disabled, TRUE,
  200.             End,
  201.             CHILD_MinHeight, ScreenFont->tf_YSize * 4,
  202.             CHILD_MinWidth, ScreenFont->tf_XSize * 16,
  203.         End;
  204.     
  205.     if (ConfLayout)
  206.     {
  207.         if (ConfWinObj = WindowObject,
  208.                 WA_DepthGadget,        TRUE,
  209.                 WA_CloseGadget,        TRUE,
  210.                 WA_DragBar,            TRUE,
  211.                 WA_Activate,        TRUE,
  212.                 WA_SizeGadget,        TRUE,
  213.                 WA_Top,                Y,
  214.                 WA_Left,            X,
  215.                 WA_PubScreen,        Scr,
  216.                 WA_Title,            GS(CONFIGURATION),
  217.                 WA_ScreenTitle,        GS(TITLE_COPYRIGHT),
  218.                 WA_AutoAdjust,         TRUE,
  219.                 WA_SimpleRefresh,     TRUE,
  220.                 WINDOW_Layout,         ConfLayout,
  221.                 WINDOW_AppPort,        AppPort,
  222.                 WINDOW_SharedPort,    WinPort,
  223.                 TAG_END))
  224.         {
  225.             LONG i;
  226.             
  227.             ConfWin = CA_OpenWindow(ConfWinObj);
  228.             
  229.             DeviceList = MakeDeviceList();
  230.             for (i = 0; Devs[i]; i++)
  231.             {
  232.                 if (!strcmp(Device, Devs[i]))
  233.                     break;
  234.             }
  235.             if (!Devs[i])
  236.                 i = 0;
  237.             SetGadgetAttrs(GList[G_Device], ConfWin, NULL, LISTBROWSER_Labels, DeviceList, LISTBROWSER_Selected, i, TAG_END);
  238.             device = i;
  239.  
  240.             if (strcmp("cd.device", Device))
  241.             {
  242.                 UnitList = MakeUnitList(Devs[i]);
  243.                 for (i = 0; i > 7 || UnitIDs[i] == Unit; i++);
  244.                 SetGadgetAttrs(GList[G_Unit], ConfWin, NULL, LISTBROWSER_Labels, UnitList, GA_Disabled, FALSE, LISTBROWSER_Selected, i, TAG_END);
  245.             }
  246.             unit = i;
  247.         
  248.             return ConfWin;
  249.         }
  250.         DisposeObject(ConfLayout);
  251.         ConfLayout = NULL;
  252.     }
  253.     ErrorMsg(GS(GUI_FAIL));
  254. }
  255.  
  256. void
  257. CloseConfWindow(void)
  258. {
  259.     if (ConfWinObj)
  260.     {
  261.         DisposeObject(ConfWinObj);
  262.         ConfWin = NULL;
  263.         ConfWinObj = NULL;
  264.         ConfLayout = NULL;
  265.         memset(&GList[G_Device], 0, (ULONG)&GList[GG_MAX3]-(ULONG)&GList[G_Device]);
  266.     }
  267.     FreeBrowserNodes(DeviceList);
  268.     DeviceList = NULL;
  269.     FreeBrowserNodes(UnitList);
  270.     UnitList = NULL;
  271. }
  272.  
  273. void
  274. ConfWindowIDCMP(void)
  275. {
  276.     BOOL close = FALSE;
  277.     ULONG result;
  278.     WORD code;
  279.     
  280.     if (!ConfWinObj)
  281.         return;
  282.         
  283.     while ((result = CA_HandleInput(ConfWinObj,&code)) != WMHI_LASTMSG)
  284.     {
  285.         /* CA_HandleInput (aka. WM_HANDLEINPUT) will translate keyboard events
  286.          * into GADGETUPs on its own */
  287.         switch (result & WMHI_CLASSMASK)
  288.         {
  289.         case WMHI_CLOSEWINDOW:
  290.             close = TRUE;
  291.             break;
  292.             
  293.         case WMHI_GADGETUP:
  294.             switch(result & WMHI_GADGETMASK)
  295.             {
  296.             case G_Device:
  297.                 if (code != device)
  298.                 {
  299.                     if (SetGadgetAttrs(GList[G_Unit], ConfWin, NULL, LISTBROWSER_Labels, &dummyList, GA_Disabled, TRUE, TAG_END))
  300.                         RefreshGList(GList[G_Unit], ConfWin, NULL, 1);
  301.                     FreeBrowserNodes(UnitList);
  302.                     if (strcmp("cd.device", Devs[code]))
  303.                     {
  304.                         UnitList = MakeUnitList(Devs[code]);
  305.                         if (SetGadgetAttrs(GList[G_Unit], ConfWin, NULL, LISTBROWSER_Labels, UnitList, GA_Disabled, FALSE, TAG_END))
  306.                             RefreshGList(GList[G_Unit], ConfWin, NULL, 1);
  307.                     }
  308.                     else
  309.                     {
  310.                         UnitList = NULL;
  311.                         memset(UnitIDs, 0, sizeof(UnitIDs));
  312.                         unit = 0;
  313.                     }
  314.                     device = code;
  315.                 }
  316.                 break;
  317.  
  318.             case G_Unit:
  319.                 unit = code;
  320.                 break;
  321.             
  322.             case G_Select:
  323.                 Device = Devs[device];
  324.                 Unit = UnitIDs[unit];
  325.                 if (Init_Device() == 0)
  326.                     close = TRUE;
  327.                 break;
  328.             }
  329.         }
  330.     }
  331.     if (close)
  332.         CloseConfWindow();
  333. }
  334.